<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="demo">
        <button-counter></button-counter>
        <button-counter></button-counter>
        <hr>
        <blog-post v-for="post in posts" :key="post.id" :title="post.title"></blog-post>
    </div>
    <script src="../js/vue.js"></script>
    <script>
        Vue.component('button-counter',{
            data(){
                return{
                    count:0,
                }
            },
            template:`<button @click="count += 1">点击了{{count}}</button>`
        })
        // 自定义一个博客组件
        Vue.component("blog-post",{
            props:['title'],//props是用来接收外部数据的，将接收到的数据都会转换称为实例组件的属性
            // 模板
            template: "<h3>{{title}}<button-counter></button-counter></h3>"
        })
        new Vue({
            data(){
                return{
                    posts:[
                        {id:1,title: "I and my gods"}, 
                        {id:2,title:"you look at like pig"}, 
                        {id:3,title:"HaHa I think you So U"}
                    ]
                }
            }
        }).$mount("#demo")
    </script>
</body>
</html>